<template>
	<view>
		
		 
	<u-radio-group @change="choose_pay_item" placement="column" v-model="now_choose_item">
		<view class="box_shadow">
		<u-radio label="购买短信100条" name="sms100" checked   ></u-radio> 
		</view>
		<view class="box_shadow">
		<u-radio label="购买短信500条"  name="sms500" ></u-radio>
		</view>
		<view class="box_shadow">
		<u-radio label="开通标签筛选功能30天(赠送短信500条)"  name="sms_and_search"></u-radio>
		</view>
	</u-radio-group>
	
	<view style="margin-top:15rpx;margin-left: 25rpx;font-size: 12rpx;">
	<u-text color="#ff9900" text="*由于短信的特殊性，一旦充值，不支持退款"></u-text>
	 </view>
	 
	 
	<view class="pay_btn">
	
		<MxBuyButton class="cmp-buy-button" :coupon_price="coupon_price" :total="detail.price" @buy="buy" />
	</view>
	
	

	 
 
	</view>
</template>

<script>
	import MxBuyButton from '@/components/common/MxBuyButton.vue';
	import coupon from '@/components/coolc-coupon/coupon';
	import * as OrderApi from '@/api/order.js';
	import {
		wxPayment
	} from '@/utils/app'
	export default {
		components: {
			MxBuyButton,
			coupon
		},
		data() {
			return {
				id: 0,
				detail: {},
				coupon_price:"",
				now_choose_item:"sms100",
				now_event_id:""
			}
		},
		onLoad(e) {
			this.now_choose_item = e.item
			this.now_event_id    = e.event_nid
			console.log("e.item",e)
			console.log("now_choose_item",this.now_choose_item)

			this.choose_pay_item()
		 
		},
		methods: {
			
			choose_pay_item()
			{
				console.log("now_choose_item",this.now_choose_item)
				if(this.now_choose_item == 'sms100'){this.coupon_price='10'}
				if(this.now_choose_item == 'sms500'){this.coupon_price='35'}
				if(this.now_choose_item == 'sms_and_search'){this.coupon_price='50'}
			},

			buy() {
				let event_nid = this.now_event_id
				
				console.log("点击了买套餐了")
				OrderApi.add_sms_set({
					user_id: uni.getStorageSync('user_id'),
					sms_set: this.now_choose_item,
					coupon_id: this.coupon_id,
				}).then(res => {
					if (res.status == 200) {
							wxPayment(res.info)
							.then(() => {
								this.$success('支付中，请勿中断操作...')
								console.log("now_event_id",this.now_event_id) 
								
								setTimeout(function() { 
									uni.redirectTo({
										url: '/pages/charge/pay-success?event='+event_nid
									});
								}, 1000);
							})
							.catch(err => this.$error('订单未支付') )
							.finally(() => {
							//console.log(wxPayment(res.info)) 
							})
					} 
			 
					else {
						this.$error(res.info)
					}


				})

			},
			

			     

		}
	}
</script>



<style scoped lang="scss">
	@import url("asset/style.css");
</style>